package cn.edu.scnu.semart.goods.mapper;

import cn.edu.scnu.semart.model.goods.Comment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 商品评论Mapper接口
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    /**
     * 根据商品ID分页查询评论
     * @param page 分页参数
     * @param goodsId 商品ID
     * @return 分页结果
     */
    IPage<Comment> selectCommentsByGoodsId(Page<Comment> page, @Param("goodsId") Integer goodsId);

    /**
     * 获取用户收到的评价列表
     * @param page 分页参数
     * @param userId 用户ID列表
     * @return 分页结果
     */
    @Select("<script>" +
            "SELECT c.* FROM goods_comment c " +
            "JOIN goods g ON c.goods_id = g.id " +
            "WHERE g.user_id = #{userId} " +
            "AND c.status = 1 " +
            "AND c.deleted = 0 " +
            "AND g.deleted = 0 " +
            "ORDER BY c.create_time DESC" +
            "</script>")
    IPage<Comment> selectReceivedComments(Page<Comment> page, @Param("userId") Integer userId);
} 